package com.shujia

import scala.collection.mutable

object Demo22map {

  def main(args: Array[String]): Unit = {

    /**
      * map   kv
      *
      */

    val map: Map[String, String] = Map("001" -> "张三", "002" -> "李四", ("003", "王五"))

    println(map)

    //通过key获取value
    println(map.get("002"))
    println(map("001"))


    //可变map
    val hashMap: mutable.HashMap[String, String] = new mutable.HashMap[String, String]()

    //增加元素
    hashMap.put("001", "张三")

    hashMap += "002" -> "李四"


    println(hashMap)


    //如果存在返回对应的value 如果不存在返回默认值
    println(hashMap.getOrElse("008", "默认值"))


    println(hashMap.keys)
    println(hashMap.values.toList)

  }

}
